package cn.tedu.coolshark.controller;

import cn.tedu.coolshark.entity.Category;
import cn.tedu.coolshark.mapper.CategoryMapper;
import cn.tedu.coolshark.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategoryController {

    @Autowired(required = false)
    CategoryMapper mapper;

    @Autowired(required = false)
    ProductMapper productMapper;

    /*保证请求路径唯一*/
    @RequestMapping("/category/select")
    public List<Category> select(){

        return mapper.select();

    }

    @RequestMapping("/category/delete")
    public void delete(int id){

        System.out.println("id = " + id);
        mapper.deleteById(id);
        //删除和该分类相关的商品
        productMapper.deleteByCid(id);

    }

    @RequestMapping("/category/insert")
    //自动封装
    public void insert(Category category){

        System.out.println("category = " + category);
        mapper.insert(category);

    }

}
